package com.zhangshihao.day63springbootdemo.controller;

import com.zhangshihao.day63springbootdemo.entity.MailProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MailController {
   @Autowired
    private JavaMailSender mailSender;
   @Autowired
    private MailProperties mailProperties;
   @Value("${spring.mail.username}")
    private String from;

   @PostMapping("/sendMail")
    public String sendMail( String to, String subject,String content){
       SimpleMailMessage message = new SimpleMailMessage();
       message.setFrom(from);
       message.setTo(to);
       message.setSubject(subject);
       message.setText(content);
       mailSender.send(message);
       return "success";
   }
}
